$(function() {
	document.title = "t-io demo";
});

/**
 * 封装的一个小方法
 * 重点提醒：ajax请求要用tio提供的ajax.post()或ajax.get()，参数和jquery一样
 * @param {*} form 要提交的form
 * @param {*} requestpath controller的请求路径，譬如:"/user/save"、"/role/save""
 */
function s(form, requestpath) {
	this.success = function(form) {
		ajax.post(requestpath, {
			data: $(form).serialize(),
			success: function(resp) {
				if (resp.ok) {
					layer.msg('操作成功');
				} else {
					layer.alert(resp.msg);
				}
			}
		});
	};
	
	this.success(form);
}



//分页查询
var laypage = layui.laypage;
var table = layui.table;

var pageNumber = getQueryString("pageNumber") || 1;
var pageSize = getQueryString("pageSize") || 8;

function page() {
	table.render({
		elem: '#itemlist'
		, limit: pageSize
		, limits: layui_page_limits
		, request: {
			pageName: 'pageNumber' //页码的参数名称，默认：page
			, limitName: 'pageSize' //每页数据量的参数名，默认：limit
		}
		, done: function (res, curr, count) {
			layui_page_done(res.pageNumber, res.pageSize);
		}
		, url: path('/demo/page') //数据接口
		, parseData: layui_page_parseData
		, page: true //开启分页
		, cols: [[ //表头
			{
				field: 'id', width: 200, title: 'id', sort: false
			},
			{
				field: 'intx', width: 200, title: 'intx', sort: false
			},
			{
				field: 'doublex', width: 200, title: 'doublex', sort: false
			},
			{
				field: 'stringx', width: 200, title: 'stringx', sort: false
			},
			{
				field: 'datex', width: 200, title: 'datex', sort: false
			}
		]]
	});

}


